package controller;

import java.util.ArrayList;
import java.util.List;

import javax.faces.bean.ApplicationScoped;
import javax.faces.bean.ManagedBean;

import model.Distr;
import model.DistrDAO;
import model.User;
import model.UserDAO;

@ApplicationScoped
@ManagedBean
public class DistrsBean {
	
	private Long newDistrId;
	
	private String newDistrName;
	
	private String newDistrTown;
	
	private Distr selectedDistr;
	
	private List<Distr> distrs = new ArrayList<Distr>();
	
	public DistrsBean() {
		distrs = tests.PopulateData.populateDistrsData();
		for (int i = 0; i < distrs.size(); i++) {
			DistrDAO.addDistr(distrs.get(i));
		}
	}

	public String getNewDistrName() {
		return newDistrName;
	}

	public List<Distr> getDistrs() {
		return distrs;
	}

	public void setNewDistrName(String newDistrName) {
		this.newDistrName = newDistrName;
	}

	public void setDistrs(List<Distr> distrs) {
		this.distrs = distrs;
	}
	
	public void addDistr() {
		Distr distr = new Distr (getNewDistrId(), getNewDistrName(), getNewDistrTown());
		distrs.add(distr);
		DistrDAO.addDistr(distr);
	}

	public Distr getSelectedDistr() {
		return selectedDistr;
	}

	public void setSelectedDistr(Distr selectedDistr) {
		this.selectedDistr = selectedDistr;
	}

	public String getNewDistrTown() {
		return newDistrTown;
	}

	public void setNewDistrTown(String newDistrTown) {
		this.newDistrTown = newDistrTown;
	}

	public Long getNewDistrId() {
		return newDistrId;
	}

	public void setNewDistrId(Long newDistrId) {
		this.newDistrId = newDistrId;
	}
}
